﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using XChipTool.Enties;
using System.IO.Ports;
using System.Configuration;
using SerialPortHelperLib;
using XChip_Common;
using BinAnalysisHelp;

namespace XChipTool
{
    public partial class XChip_Lite_HDR_Ae : DevExpress.XtraEditors.XtraUserControl
    {
        public SerialPort sPortTemp;
        private bool isRead = false;
        private KeyEventArgs keyEnter = new KeyEventArgs(Keys.Enter);//用来手动触发文本框下发配置
        public addressregisterManager aBll;
        private List<addressregister> xChipHDRAe;
        private List<addressregister> XChipHDR;

        public bool IsUsbOpen = false;
        //记录是否使用I2C设备读写
        public bool m_open = false;
        //是否在获取数据
        private bool isWrite = false;
        public List<addressregister> XChipHDRAe
        {
            get
            {
                if (null == xChipHDRAe)
                {
                    xChipHDRAe = aBll.GetList(c => c.ChipType == ConfigurationManager.AppSettings["xc151_ChipType"] && (c.Classify == "HDR_AE" || c.Classify == "Common"));
                   }
                return xChipHDRAe;
            }

            set
            {
                xChipHDRAe = value;
            }
        }

        public XChip_Lite_HDR_Ae()
        {
            //if (null == xChipHDRAe)
            //{
            //       //aBll = new addressregisterManager();
            //       //xChipHDRAe = aBll.GetList(c => c.ChipType == ConfigurationManager.AppSettings["xc151_ChipType"] && (c.Classify == "HDR_AE" || c.Classify == "Common"));
            //}
            XChipHDR = aBll.GetList(c => c.ChipType == ConfigurationManager.AppSettings["xc151_ChipType"] && (c.Classify == "HDR"));

            InitializeComponent();
        }
        public XChip_Lite_HDR_Ae(SerialPort _sPortTemp, addressregisterManager _aBll , bool _IsUsbOpen = false)
        {
            sPortTemp = _sPortTemp;
            aBll = _aBll;
            XChipHDR = aBll.GetList(c => c.ChipType == ConfigurationManager.AppSettings["xc151_ChipType"] && (c.Classify == "HDR"));
            IsUsbOpen = _IsUsbOpen;
            InitializeComponent();
        }
        private void btn_Refresh_Click(object sender, EventArgs e)
        {
            //if (AE_WEIGHT_EN.Checked)
            //{
            //    SerialSend.WriteRegister(0x20000077,0x01, sPortTemp);
            //}
        }

        private Control[] Controls_Find(string str)
        {
            //var t =   this.Controls.Find(type, true);
            List<Control> listc = new List<Control>();
            System.Reflection.FieldInfo[] fieldInfo = this.GetType().GetFields(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
           
            for (int i = 0; i < fieldInfo.Length; i++)
            {
                if (fieldInfo[i].Name.ToLower().Contains(str.ToLower())&& !listc.Exists(c=>c.Name.ToLower()==(fieldInfo[i].Name.ToLower())))
                {
                    listc.AddRange(this.Controls.Find(fieldInfo[i].Name, true));
                    //break;
                }
            }
            return listc.ToArray();
        }

        /// <summary>
        /// 获取所有数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void simpleButton5_Click(object sender, EventArgs e)
        {
            try
            {
                if (IsUsbOpen)
                {

                }
                else
                {
                    if (!sPortTemp.IsOpen)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show("可用端口未打开");
                        return;
                    }
                }
                isRead = true;
                isWrite = true;
                WaitBefore.Start("读取中", "正在加载中", 10);
                List<string> NameList = new List<string>();

                for (int i = 0; i < xChipHDRAe.Count; i++)
                {
                    if (xChipHDRAe[i].NameType.Contains("tome_mappinglist"))
                    {

                    }
                    var type = AppHelper.NameTypeToString(xChipHDRAe[i].NameType);
                    if (NameList.Exists(c => c.ToLower() == (type)))
                    {
                        continue;
                    }
                    ////加上单选框的_en
                    //if (xChipHDRAe[i].ControlType == "1")
                    //{
                    //    type = xChipHDRAe[i].NameType;
                    //}
                    var col = Controls_Find(type);

                    foreach (var item in col)
                    {
                        if (item is TextEdit)
                        {
                            var nList = xChipHDRAe.Where(c => c.NameType.ToLower().Contains(item.Name.ToString().ToLower()) && c.ControlType == "0").ToList();
                            if (item.Name.ToLower() == type.ToLower())
                            {
                                nList = xChipHDRAe.Where(c => c.NameType.ToLower() == (item.Name.ToString().ToLower()) && c.ControlType == "0").ToList();
                            }
                            if (nList.Count == 0)
                            {
                                nList = xChipHDRAe.Where(c => c.NameType.ToLower().Contains(item.Name.ToString().ToLower()) && c.ControlType == "0").ToList();
                            }
                            if (nList.Count == 1)
                            {
                                var Val = SerialSend.ReadRegister(Convert.ToUInt32(nList[0].Address, 16), sPortTemp).ToString("X");
                                item.Text = BitsHelp.GetBitsToUint(nList[0].Bits, nList[0].Hex, Val).ToString("X");
                            }
                            else
                            {
                                string Val = string.Empty;
                                //这里默认为是有多个寄存器  一个文本框的情况进行处理
                                if (nList.Exists(c => c.NameType.ToLower().Contains("_h")))
                                {
                                    Val += SerialSend.ReadRegister(Convert.ToUInt32(nList.Find(c => c.NameType.ToLower().Contains("_h")).Address, 16), sPortTemp).ToString("X2");
                                }
                                if (nList.Exists(c => c.NameType.ToLower().Contains("_m1")))
                                {
                                    Val += SerialSend.ReadRegister(Convert.ToUInt32(nList.Find(c => c.NameType.ToLower().Contains("_m1")).Address, 16), sPortTemp).ToString("X2");
                                }
                                if (nList.Exists(c => c.NameType.ToLower().Contains("_m0")))
                                {
                                    Val += SerialSend.ReadRegister(Convert.ToUInt32(nList.Find(c => c.NameType.ToLower().Contains("_m0")).Address, 16), sPortTemp).ToString("X2");
                                }
                                if (nList.Exists(c => c.NameType.ToLower().Contains("_l")))
                                {
                                    if (nList.Exists(c => c.NameType.ToLower().Substring(c.NameType.Length - 2).Contains("_l")))
                                    {
                                        Val += SerialSend.ReadRegister(Convert.ToUInt32(nList.Find(c => c.NameType.ToLower().Substring(c.NameType.Length - 2).Contains("_l")).Address, 16), sPortTemp).ToString("X2");
                                    }
                                    else
                                    {
                                        Val += SerialSend.ReadRegister(Convert.ToUInt32(nList.Last(c => c.NameType.ToLower().Contains("_l")).Address, 16), sPortTemp).ToString("X2");
                                    }
                                }

                                item.Text = Val;
                            }
                        }
                        else if (item is CheckEdit)
                        {
                            var nList = xChipHDRAe.Where(c => c.NameType.ToLower().Contains(item.Name.ToString().ToLower()) && c.ControlType == "1").ToList();
                            if (nList.Count == 1)
                            {
                                var Val = SerialSend.ReadRegister(Convert.ToUInt32(nList[0].Address, 16), sPortTemp).ToString("X");
                                (item as CheckEdit).Checked = BitsHelp.GetBitsCheckedToBool(nList[0].Bits, nList[0].Hex, Val) == 0;
                            }
                        }
                        NameList.Add(item.Name);

                    }

                    //NameList.Add(type);
                }
                //Flicker_Long
                // var fl =  SerialSend.ReadRegister(Convert.ToUInt32(xChipHDRAe.Find(c => c.NameType.ToLower().Contains("Flicker_Long".ToLower()) && c.ControlType == "0").Address, 16), sPortTemp);
                //switch (fl)
                //{
                //    case 0x0:
                //        Flicker_Long.SetItemCheckState(0, CheckState.Checked);
                //        break;
                //    case 0x2:
                //        Flicker_Long.SetItemCheckState(1, CheckState.Checked);
                //        break;
                //    case 0x1:
                //        Flicker_Long.SetItemCheckState(1, CheckState.Checked);
                //        break;
                //    default:
                //        Flicker_Long.SetItemCheckState(-1, CheckState.Unchecked);
                //        break;
                //}

                var nValue = SerialSend.ReadRegister(Convert.ToUInt32(xChipHDRAe.Find(c => c.NameType.ToLower().Contains("Flicker_Long".ToLower()) && c.ControlType == "0").Address, 16), sPortTemp);
                if (nValue == 0) //disable
                {
                    Flicker_Long.Items[0].CheckState = CheckState.Unchecked;
                    Flicker_Long.Items[1].CheckState = CheckState.Unchecked;
                }
                else if (nValue == 1) //60hz
                {
                    Flicker_Long.Items[0].CheckState = CheckState.Unchecked;
                    Flicker_Long.Items[1].CheckState = CheckState.Checked;
                }
                else if (nValue == 2) //50hz
                {
                    Flicker_Long.Items[0].CheckState = CheckState.Checked;
                    Flicker_Long.Items[1].CheckState = CheckState.Unchecked;
                }

                NameList = new List<string>();
                for (int i = 0; i < XChipHDR.Count; i++)
                {
                    if (XChipHDR[i].NameType.Contains("tome_mappinglist"))
                    {

                    }
                    var type = AppHelper.NameTypeToString(XChipHDR[i].NameType);
                    //加上单选框的_en
                    if (XChipHDR[i].ControlType == "1")
                    {
                        type = XChipHDR[i].NameType;
                    }
                    var col = this.Controls.Find(type, true);

                    foreach (var item in col)
                    {
                        if (NameList.Exists(c => c == (type)))
                        {
                            continue;
                        }
                        else
                        {

                            if (item is TextEdit)
                            {

                                var nList = XChipHDR.Where(c => c.NameType.ToLower().Contains(item.Name.ToString().ToLower()) && c.ControlType == "0").ToList();
                                if (nList.Count == 1)
                                {
                                    var Val = SerialSend.ReadRegister(Convert.ToUInt32(nList[0].Address, 16), sPortTemp).ToString("X");
                                    item.Text = BitsHelp.GetBitsToUint(nList[0].Bits, nList[0].Hex, Val).ToString("X");
                                }
                                else
                                {
                                    var listsum = nList.Select(c => c.Address).Distinct().ToList();
                                    string Val = string.Empty;
                                    if (1 == listsum.Count())
                                    {

                                    }
                                    else
                                    {

                                    }

                                    //这里默认为是有多个寄存器  一个文本框的情况进行处理
                                    if (nList.Exists(c => c.NameType.ToLower().Contains("_h")))
                                    {
                                        Val += SerialSend.ReadRegister(Convert.ToUInt32(nList.Find(c => c.NameType.ToLower().Contains("_h")).Address, 16), sPortTemp).ToString("X2");
                                    }
                                    if (nList.Exists(c => c.NameType.ToLower().Contains("_m0")))
                                    {
                                        Val += SerialSend.ReadRegister(Convert.ToUInt32(nList.Find(c => c.NameType.ToLower().Contains("_m0")).Address, 16), sPortTemp).ToString("X2");
                                    }

                                    if (nList.Exists(c => c.NameType.ToLower().Substring(c.NameType.Length - 2).Contains("_l")))
                                    {
                                        Val += SerialSend.ReadRegister(Convert.ToUInt32(nList.Find(c => c.NameType.ToLower().Substring(c.NameType.Length - 2).Contains("_l")).Address, 16), sPortTemp).ToString("X2");
                                    }
                                    item.Text = Val;
                                }
                            }
                            else if (item is CheckEdit)
                            {
                                var nList = XChipHDR.Where(c => c.NameType.ToLower().Contains(item.Name.ToString().ToLower()) && c.ControlType == "1").ToList();
                                if (nList.Count == 1)
                                {
                                    var Val = SerialSend.ReadRegister(Convert.ToUInt32(nList[0].Address, 16), sPortTemp).ToString("X");
                                    (item as CheckEdit).Checked = BitsHelp.GetBitsCheckedToBool(nList[0].Bits, nList[0].Hex, Val) == 0;
                                }
                            }


                        }
                    }
                    NameList.Add(type);
                }
                var combine = SerialSend.ReadRegister((Convert.ToUInt32(XChipHDR.Where(c => c.NameType.ToLower() == "combine_mode_en".ToLower()).First().Address, 16)), sPortTemp);
                if (combine == 0x80)
                {
                    Mode_switch.Properties.Items[3].Enabled = false;
                }
                else if (combine == 0xC0)
                {
                    Mode_switch.Properties.Items[3].Enabled = true;
                }
                //Flicker_Short
                //var fs = SerialSend.ReadRegister(Convert.ToUInt32(xChipHDRAe.Find(c => c.NameType.ToLower().Contains("Flicker_Short".ToLower()) && c.ControlType == "0").Address, 16), sPortTemp);
                //switch (fs)
                //{
                //    case 0x0:
                //        Flicker_Short.SetItemCheckState(0, CheckState.Checked);
                //        break;
                //    case 0x2:
                //        Flicker_Short.SetItemCheckState(1, CheckState.Checked);
                //        break;
                //    case 0x1:
                //        Flicker_Short.SetItemCheckState(1, CheckState.Checked);
                //        break;
                //    default:
                //        Flicker_Short.SetItemCheckState(0, CheckState.Unchecked);
                //        Flicker_Short.SetItemCheckState(1, CheckState.Unchecked);
                //        Flicker_Short.SetItemCheckState(2, CheckState.Unchecked);
                //        break;
                //}
                //Flicker_Very_Short
                //var fvs = SerialSend.ReadRegister(Convert.ToUInt32(xChipHDRAe.Find(c => c.NameType.ToLower().Contains("Flicker_Very_Short".ToLower()) && c.ControlType == "0").Address, 16), sPortTemp);
                //switch (fvs)
                //{
                //    case 0x0:
                //        Flicker_Very_Short.SetItemCheckState(0, CheckState.Checked);
                //        break;
                //    case 0x2:
                //        Flicker_Very_Short.SetItemCheckState(1, CheckState.Checked);
                //        break;
                //    case 0x1:
                //        Flicker_Very_Short.SetItemCheckState(1, CheckState.Checked);
                //        break;
                //    default:
                //        Flicker_Very_Short.SetItemCheckState(0, CheckState.Unchecked);
                //        Flicker_Very_Short.SetItemCheckState(1, CheckState.Unchecked);
                //        Flicker_Very_Short.SetItemCheckState(2, CheckState.Unchecked);
                //        break;
                //}
                //HDRAE_SpeedModeradio
                //HDRAE_SpeedModeradio.SelectedIndex = (int)SerialSend.ReadRegister(Convert.ToUInt32(xChipHDRAe.Find(c => c.NameType.ToLower().Contains("HDRAE_SpeedModeradio".ToLower()) && c.ControlType == "0").Address, 16), sPortTemp);

                //Statusvalue();
                //isRead = false;
                //if (speed_mode_man_en.Checked)
                //{
                //    if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{HDRAE_SpeedModeradio.Name}".ToLower()))
                //    {
                //        var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{HDRAE_SpeedModeradio.Name}".ToLower());
                //        var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, "1".ToString());
                //        SetHDRAeRegister(model, Val);
                //    }
                //} var combine = SerialSend.ReadRegister((Convert.ToUInt32(hdrList.Where(c => c.NameType.ToLower() == "combine_mode_en".ToLower()).First().Address, 16)), sPortTemp);
                if (combine == 0x80)
                {
                    Mode_switch.Properties.Items[3].Enabled = false;
                }
                else if (combine == 0xC0)
                {
                    Mode_switch.Properties.Items[3].Enabled = true;
                }
                var HDRmodeVal = SerialSend.ReadRegister(Convert.ToUInt32(XChipHDR.Where(c => c.NameType.ToLower() == "HDRmode0".ToLower()).First().Address, 16), sPortTemp).ToString("X");
                bool HDRmode0 = BitsHelp.GetBitsCheckedToBool(XChipHDR.Where(c => c.NameType.ToLower() == "HDRmode0".ToLower()).First().Bits, XChipHDR.Where(c => c.NameType.ToLower() == "HDRmode0".ToLower()).First().Hex, HDRmodeVal) == 0;
                HDRmodeVal = SerialSend.ReadRegister(Convert.ToUInt32(XChipHDR.Where(c => c.NameType.ToLower() == "HDRmode1".ToLower()).First().Address, 16), sPortTemp).ToString("X");
                bool HDRmode1 = BitsHelp.GetBitsCheckedToBool(XChipHDR.Where(c => c.NameType.ToLower() == "HDRmode1".ToLower()).First().Bits, XChipHDR.Where(c => c.NameType.ToLower() == "HDRmode1".ToLower()).First().Hex, HDRmodeVal) == 0;
                HDRmodeVal = SerialSend.ReadRegister(Convert.ToUInt32(XChipHDR.Where(c => c.NameType.ToLower() == "HDRmode2".ToLower()).First().Address, 16), sPortTemp).ToString("X");
                bool HDRmode2 = BitsHelp.GetBitsCheckedToBool(XChipHDR.Where(c => c.NameType.ToLower() == "HDRmode2".ToLower()).First().Bits, XChipHDR.Where(c => c.NameType.ToLower() == "HDRmode2".ToLower()).First().Hex, HDRmodeVal) == 0;
                if (HDRmode0 && !HDRmode1 && !HDRmode1)
                {
                    Mode_switch.SelectedIndex = 0;
                }
                else if (!HDRmode0 && !HDRmode1 && !HDRmode2)
                {
                    Mode_switch.SelectedIndex = 1;
                }
                else if (!HDRmode0 && HDRmode1 && !HDRmode2)
                {
                    Mode_switch.SelectedIndex = 2;
                }
                else if (!HDRmode0 && !HDRmode1 && HDRmode2)
                {
                    Mode_switch.SelectedIndex = 3;
                }
                nValue = SerialSend.ReadRegister(Convert.ToUInt32(xChipHDRAe.Find(c => c.NameType.ToLower().Contains("HDRAE_SpeedModeradio".ToLower()) && c.ControlType == "0").Address, 16), sPortTemp);
                if (nValue == 1)
                {
                    speed_mode_man_en.Checked = true;
                }
                else
                {
                    speed_mode_man_en.Checked = false;
                }
                EnShowHide();
            }
            catch (Exception ex)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show("出现错误信息："+ex.ToString());

            }
            finally{
                isRead = false;
                isWrite = false;
                WaitBefore.Close();
            }
           
        }

        private void simpleButton3_Click(object sender, EventArgs e)
        {
            if (IsUsbOpen)
            {

            }
            else
            {
                if (!sPortTemp.IsOpen)
                {
                    DevExpress.XtraEditors.XtraMessageBox.Show("可用端口未打开");
                    return;
                }
            }
            List<string> listfiltration = new List<string> { "Expo_Long", "Expo_Short", "Expo_VeryShort", "GainReadOnly", "TargetY_L", "TargetY_S" };

            isRead = true;
            WaitBefore.Start("读取中", "正在加载中", 10);
            List<string> NameList = new List<string>();

            for (int i = 0; i < xChipHDRAe.Count; i++)
            {
                if (xChipHDRAe[i].NameType.Contains("Expo_L"))
                {

                }
                var type = AppHelper.NameTypeToString(xChipHDRAe[i].NameType);
                if (NameList.Exists(c => c.ToLower() == (type)))
                {
                    continue;
                }
               
                ////加上单选框的_en
                //if (xChipHDRAe[i].ControlType == "1")
                //{
                //    type = xChipHDRAe[i].NameType;
                //}
                var col = Controls_Find(type);

                foreach (var item in col)
                {
                    if (!listfiltration.Exists(c => c.Contains(item.Name.ToString())))
                    {
                        continue;
                    }
                    if (item is TextEdit)
                    {
                        var nList = xChipHDRAe.Where(c => c.NameType.ToLower().Contains(item.Name.ToString().ToLower()) && c.ControlType == "0").ToList();
                        if (item.Name.ToLower() == type.ToLower())
                        {
                            nList = xChipHDRAe.Where(c => c.NameType.ToLower() == (item.Name.ToString().ToLower()) && c.ControlType == "0").ToList();
                        }
                        if (nList.Count == 0)
                        {
                            nList = xChipHDRAe.Where(c => c.NameType.ToLower().Contains(item.Name.ToString().ToLower()) && c.ControlType == "0").ToList();
                        }
                        if (nList.Count == 1)
                        {
                            var Val = SerialSend.ReadRegister(Convert.ToUInt32(nList[0].Address, 16), sPortTemp).ToString("X");
                            item.Text = BitsHelp.GetBitsToUint(nList[0].Bits, nList[0].Hex, Val).ToString("X");
                        }
                        else
                        {
                            string Val = string.Empty;
                            //这里默认为是有多个寄存器  一个文本框的情况进行处理
                            if (nList.Exists(c => c.NameType.ToLower().Contains("_h")))
                            {
                                Val += SerialSend.ReadRegister(Convert.ToUInt32(nList.Find(c => c.NameType.ToLower().Contains("_h")).Address, 16), sPortTemp).ToString("X2");
                            }
                            if (nList.Exists(c => c.NameType.ToLower().Contains("_m1")))
                            {
                                Val += SerialSend.ReadRegister(Convert.ToUInt32(nList.Find(c => c.NameType.ToLower().Contains("_m1")).Address, 16), sPortTemp).ToString("X2");
                            }
                            if (nList.Exists(c => c.NameType.ToLower().Contains("_m0")))
                            {
                                Val += SerialSend.ReadRegister(Convert.ToUInt32(nList.Find(c => c.NameType.ToLower().Contains("_m0")).Address, 16), sPortTemp).ToString("X2");
                            }
                            if (nList.Exists(c => c.NameType.ToLower().Contains("_l")))
                            {
                                if (nList.Exists(c => c.NameType.ToLower().Substring(c.NameType.Length - 2).Contains("_l")))
                                {
                                    Val += SerialSend.ReadRegister(Convert.ToUInt32(nList.Find(c => c.NameType.ToLower().Substring(c.NameType.Length - 2).Contains("_l")).Address, 16), sPortTemp).ToString("X2");
                                }
                                else
                                {
                                    Val += SerialSend.ReadRegister(Convert.ToUInt32(nList.Last(c => c.NameType.ToLower().Contains("_l")).Address, 16), sPortTemp).ToString("X2");
                                }
                            }

                            item.Text = Val;
                        }
                    }
                    else if (item is CheckEdit)
                    {
                        var nList = xChipHDRAe.Where(c => c.NameType.ToLower().Contains(item.Name.ToString().ToLower()) && c.ControlType == "1").ToList();
                        if (nList.Count == 1)
                        {
                            var Val = SerialSend.ReadRegister(Convert.ToUInt32(nList[0].Address, 16), sPortTemp).ToString("X");
                            (item as CheckEdit).Checked = BitsHelp.GetBitsCheckedToBool(nList[0].Bits, nList[0].Hex, Val) == 0;
                        }
                    }
                    NameList.Add(item.Name);

                }

                //NameList.Add(type);
            }
            isRead = false;
            WaitBefore.Close();



        }
        /// <summary>
        /// 加入提示信息和正则判断
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void XChip_HDR_Ae_Load(object sender, EventArgs e)
        {
            List<string> NameList = new List<string>();
            for (int i = 0; i < XChipHDRAe.Count; i++)
            {
              
                var type = AppHelper.NameTypeToString(XChipHDRAe[i].NameType);
                if (NameList.Exists(c => c.ToLower() == (type)))
                {
                    continue;
                }
                var col = Controls_Find(type);
                foreach (var item in col)
                {
                    if (item is TextEdit)
                    {
                        //声明一个SuerToolTip
                        DevExpress.Utils.SuperToolTip graduationBatchSuperToolTip = new DevExpress.Utils.SuperToolTip();
                        //声明一个ToolTipTitleItem,保存标题
                        DevExpress.Utils.ToolTipTitleItem toolTipTitleItem = new DevExpress.Utils.ToolTipTitleItem();
                        String tooltips = "";

                        if (!string.IsNullOrEmpty(XChipHDRAe[i].Bit_Wide))
                        {
                            tooltips += $"位宽={XChipHDRAe[i].Bit_Wide}";
                        }
                        if (!string.IsNullOrEmpty(XChipHDRAe[i].Bit_Accuracy))
                        {
                            tooltips += $"|精度={XChipHDRAe[i].Bit_Accuracy}";
                        }
                        //设置标题文字
                        toolTipTitleItem.Text = tooltips;
                        //把标题添加到SuerToolTip
                        graduationBatchSuperToolTip.Items.Add(toolTipTitleItem);
                        //指定控件的SuperTip

                        ((TextEdit)item).SuperTip = graduationBatchSuperToolTip;
                        //正则判断
                        ((TextEdit)item).Properties.Mask.MaskType = DevExpress.XtraEditors.Mask.MaskType.RegEx;
                        ((TextEdit)item).Properties.Mask.EditMask = BitsHelp.GetBitsToMask(XChipHDRAe[i].Bits, XChipHDRAe[i].Bit_Wide, XChipHDRAe.Where(c => c.NameType.ToLower().Contains(type) && c.ControlType == "0").Select(c => c.Bits).ToList());

                    }
                    NameList.Add(item.Name);

                }
            }
            for (int i = 0; i < XChipHDR.Count; i++)
            {

                var type = AppHelper.NameTypeToString(XChipHDR[i].NameType);

                var col = this.Controls.Find(type, true);


                foreach (var item in col)
                {
                    if (item is TextEdit)
                    {
                        //声明一个SuerToolTip
                        DevExpress.Utils.SuperToolTip graduationBatchSuperToolTip = new DevExpress.Utils.SuperToolTip();
                        //声明一个ToolTipTitleItem,保存标题
                        DevExpress.Utils.ToolTipTitleItem toolTipTitleItem = new DevExpress.Utils.ToolTipTitleItem();
                        String tooltips = "";
                        if (!string.IsNullOrEmpty(XChipHDR[i].Bit_Wide))
                        {
                            tooltips += $"位宽={XChipHDR[i].Bit_Wide}";
                        }
                        if (!string.IsNullOrEmpty(XChipHDR[i].Bit_Accuracy))
                        {
                            tooltips += $"|精度={XChipHDR[i].Bit_Accuracy}";
                        }
                        //设置标题文字
                        toolTipTitleItem.Text = tooltips;
                        //把标题添加到SuerToolTip
                        graduationBatchSuperToolTip.Items.Add(toolTipTitleItem);
                        //指定控件的SuperTip
                        ((TextEdit)item).SuperTip = graduationBatchSuperToolTip;
                        //正则判断
                        ((TextEdit)item).Properties.Mask.MaskType = DevExpress.XtraEditors.Mask.MaskType.RegEx;
                        ((TextEdit)item).Properties.Mask.EditMask = BitsHelp.GetBitsToMask(XChipHDR[i].Bits, XChipHDR[i].Bit_Wide, XChipHDR.Where(c => c.NameType.ToLower().Contains(type) && c.ControlType == "0").Select(c => c.Bits).ToList());
                    }
                }

            }
        }

        private void Area_Weight_01_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                Area_Weight_01_Leave(sender, null);
            }
        }
        private void SetHDRAeRegister(addressregister model, ulong add, bool isCheck = true)
        {
            if (isRead) return;
            if (IsUsbOpen)
            {
                
                if (null != BinHelp.usbList)
                {
                    uint pVule = 0x0;
                    var isbool = false;
                    if (IntPtr.Size == 8)
                    {
                        isbool = XChipUSB.UsbRegisterRead64(BinHelp.CurrentSize, ref pVule, true);
                        SerialSend.Sendser("R:0x" + (BinHelp.CurrentSize).ToString("X2"), pVule.ToString("X2"));


                    }
                    else
                    {
                        isbool = XChipUSB.UsbRegisterRead86(BinHelp.CurrentSize, ref pVule, true);
                        SerialSend.Sendser("R:0x" + (BinHelp.CurrentSize).ToString("X2"), pVule.ToString("X2"));
                    }
                    var chang = (int)(pVule >> 16); // 使用右移16位操作来获取高16位  
                    var kuang = (int)(pVule & 0xFFFF); // 使用位与操作来获取低16位  


                    BinHelp.SstBinUsbUpdateData(ref BinHelp.BinList, model.Address, add.ToString("X"), chang, kuang);
                }
            }
            else
            {

                if (null != BinHelp.lspList)
                { //编写Bin更新数据
                    var temp = SerialSend.ReadRegister(BinHelp.BootSettingIdx, sPortTemp);
                    BinHelp.SetBinUpdateData(ref BinHelp.BinList, model.Address, add.ToString("X"), (uint)temp);
                }
            }

            SerialSend.WriteRegister(Convert.ToUInt32(model.Address, 16), add, sPortTemp);
        }

        private void Area_Weight_01_Leave(object sender, EventArgs e)
        {
            if (isRead) return;
            var txtEdit = sender as DevExpress.XtraEditors.TextEdit;
            if (string.IsNullOrEmpty(txtEdit.Text)) return;

            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
        }

        private void adaptive_dr_table_01_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                adaptive_dr_table_01_Leave(sender, null);
            }
        }

        private void adaptive_dr_table_01_Leave(object sender, EventArgs e)
        {
            if (isRead) return;
            var txtEdit = sender as DevExpress.XtraEditors.TextEdit;
            if (string.IsNullOrEmpty(txtEdit.Text)) return;

            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
        }

        private void L_number_adaptive_01_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                L_number_adaptive_01_Leave(sender, null);
            }
        }

        private void L_number_adaptive_01_Leave(object sender, EventArgs e)
        {
            if (isRead) return;
            var txtEdit = sender as DevExpress.XtraEditors.TextEdit;
            if (string.IsNullOrEmpty(txtEdit.Text)) return;

            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
        }

        private void TargetY_L_adaptive_01_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                TargetY_L_adaptive_01_Leave(sender, null);
            }
        }

        private void TargetY_L_adaptive_01_Leave(object sender, EventArgs e)
        {
            if (isRead) return;
            var txtEdit = sender as DevExpress.XtraEditors.TextEdit;
            if (string.IsNullOrEmpty(txtEdit.Text)) return;

            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}_h".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}_h".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}_l".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}_l".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
        }

        private void TargetY_S_adaptive_01_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                TargetY_S_adaptive_04_Leave(sender, null);
            }
        }

        private void TargetY_S_adaptive_04_Leave(object sender, EventArgs e)
        {
            if (isRead) return;
            var txtEdit = sender as DevExpress.XtraEditors.TextEdit;
            if (string.IsNullOrEmpty(txtEdit.Text)) return;

            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}_h".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}_h".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}_l".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}_l".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
        }

        private void Max_Expo_L_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                Max_Expo_L_Leave(sender, null);
            }
        }

        private void Max_Expo_L_Leave(object sender, EventArgs e)
        {
            if (isRead) return;
            var txtEdit = sender as DevExpress.XtraEditors.TextEdit;
            if (string.IsNullOrEmpty(txtEdit.Text)) return;

            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}_h".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}_h".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}_m0".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}_m0".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}_m1".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}_m1".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}_l".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}_l".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
        }

        private void Max_Gain_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                Max_Gain_Leave(sender, null);
            }
        }

        private void Max_Gain_Leave(object sender, EventArgs e)
        {
            if (isRead) return;
            var txtEdit = sender as DevExpress.XtraEditors.TextEdit;
            if (string.IsNullOrEmpty(txtEdit.Text)) return;

            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}_h".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}_h".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}_l".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}_l".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
        }

        private void Max_Expo_S_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                Max_Expo_S_Leave(sender, null);
            }
        }

        private void Max_Expo_S_Leave(object sender, EventArgs e)
        {
            if (isRead) return;
            var txtEdit = sender as DevExpress.XtraEditors.TextEdit;
            if (string.IsNullOrEmpty(txtEdit.Text)) return;

            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}_h".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}_h".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}_m0".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}_m0".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}_m1".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}_m1".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}_l".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}_l".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
        }

        private void Max_Expo_VS_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                Max_Expo_VS_Leave(sender, null);
            }
        }

        private void Max_Expo_VS_Leave(object sender, EventArgs e)
        {
            if (isRead) return;
            var txtEdit = sender as DevExpress.XtraEditors.TextEdit;
            if (string.IsNullOrEmpty(txtEdit.Text)) return;

            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}_h".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}_h".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}_m0".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}_m0".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}_m1".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}_m1".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}_l".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}_l".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
        }

        private void trigger_timer_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                trigger_timer_Leave(sender, null);
            }
        }

        private void trigger_timer_Leave(object sender, EventArgs e)
        {
            if (isRead) return;
            var txtEdit = sender as DevExpress.XtraEditors.TextEdit;
            if (string.IsNullOrEmpty(txtEdit.Text)) return;

            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}_h".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}_h".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}_l".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}_l".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
        }

        private void dr_wave_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                dr_wave_Leave(sender, null);
            }
        }

        private void dr_wave_Leave(object sender, EventArgs e)
        {
            if (isRead) return;
            var txtEdit = sender as DevExpress.XtraEditors.TextEdit;
            if (string.IsNullOrEmpty(txtEdit.Text)) return;

            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
        }

        private void L_num_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                L_num_Leave(sender, null);
            }
        }

        private void L_num_Leave(object sender, EventArgs e)
        {
            if (isRead) return;
            var txtEdit = sender as DevExpress.XtraEditors.TextEdit;
            if (string.IsNullOrEmpty(txtEdit.Text)) return;

            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
        }

        private void TargetY_L_ex_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                TargetY_L_ex_Leave(sender, null);
            }
        }

        private void TargetY_L_ex_Leave(object sender, EventArgs e)
        {
            if (isRead) return;
            var txtEdit = sender as DevExpress.XtraEditors.TextEdit;
            if (string.IsNullOrEmpty(txtEdit.Text)) return;

            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}_h".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}_h".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}_l".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}_l".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
        }

        private void TargetY_S_ex_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                TargetY_S_ex_Leave(sender, null);
            }
        }

        private void TargetY_S_ex_Leave(object sender, EventArgs e)
        {
            if (isRead) return;
            var txtEdit = sender as DevExpress.XtraEditors.TextEdit;
            if (string.IsNullOrEmpty(txtEdit.Text)) return;

            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}_h".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}_h".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}_l".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}_l".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
        }

        private void S_num_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                S_num_Leave(sender, null);
            }
        }

        private void S_num_Leave(object sender, EventArgs e)
        {
            if (isRead) return;
            var txtEdit = sender as DevExpress.XtraEditors.TextEdit;
            if (string.IsNullOrEmpty(txtEdit.Text)) return;

            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
        }

        private void Flicker_50Hz_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                Flicker_50Hz_Leave(sender, null);
            }
        }

        private void Flicker_50Hz_Leave(object sender, EventArgs e)
        {
            if (isRead) return;
            var txtEdit = sender as DevExpress.XtraEditors.TextEdit;
            if (string.IsNullOrEmpty(txtEdit.Text)) return;

            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}_h".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}_h".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}_l".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}_l".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
        }

        private void Flicker_60Hz_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                Flicker_60Hz_Leave(sender, null);
            }
        }

        private void Flicker_60Hz_Leave(object sender, EventArgs e)
        {
            if (isRead) return;
            var txtEdit = sender as DevExpress.XtraEditors.TextEdit;
            if (string.IsNullOrEmpty(txtEdit.Text)) return;

            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}_h".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}_h".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}_l".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}_l".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
        }

        private void Flicker_Long_ItemChecking(object sender, DevExpress.XtraEditors.Controls.ItemCheckingEventArgs e)
        {
                CheckedListBoxControl chkControl = sender as CheckedListBoxControl;
               SingleSelectCheckedListBoxControls(chkControl, e.Index);
        }
        public void SingleSelectCheckedListBoxControls(CheckedListBoxControl chkControl, int index)
        {
            if (chkControl.CheckedItems.Count > 0)
            {
                for (int i = 0; i < chkControl.Items.Count; i++)
                {
                    if (i != index)
                    {
                        chkControl.SetItemCheckState(i, System.Windows.Forms.CheckState.Unchecked);
                    }
                }
            }
        }

        private void Flicker_Short_ItemChecking(object sender, DevExpress.XtraEditors.Controls.ItemCheckingEventArgs e)
        {
            CheckedListBoxControl chkControl = sender as CheckedListBoxControl;
            SingleSelectCheckedListBoxControls(chkControl, e.Index);
        }

        private void Flicker_Very_Short_ItemChecking(object sender, DevExpress.XtraEditors.Controls.ItemCheckingEventArgs e)
        {
            CheckedListBoxControl chkControl = sender as CheckedListBoxControl;
            SingleSelectCheckedListBoxControls(chkControl, e.Index);
        }

        private void Flicker_Long_ItemCheck(object sender, DevExpress.XtraEditors.Controls.ItemCheckEventArgs e)
        {
            if (isRead) return;
            var txtEdit = sender as CheckedListBoxControl;
            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}".ToLower()))
            {
                if (txtEdit.Items[0].CheckState == CheckState.Checked)//50hz
                {
                    var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}".ToLower());
                    SetHDRAeRegister(model, (ulong)0x02);
                }
                if (txtEdit.Items[1].CheckState == CheckState.Checked)//60hz
                {
                    var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}".ToLower());
                    SetHDRAeRegister(model, (ulong)0x01);
                }
                if ((txtEdit.Items[1].CheckState == CheckState.Unchecked) && (txtEdit.Items[0].CheckState == CheckState.Unchecked))//均不勾选
                {
                    var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}".ToLower());
                    SetHDRAeRegister(model, (ulong)0x00);
                }
            }
            EnShowHide();

        }

        private void Flicker_Short_ItemCheck(object sender, DevExpress.XtraEditors.Controls.ItemCheckEventArgs e)
        {
            if (isRead) return;
            var txtEdit = sender as CheckedListBoxControl;
            if (string.IsNullOrEmpty(txtEdit.Text)) return;

            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.SelectedValue.ToString());
                SetHDRAeRegister(model, Val);
            }
        }

        private void Flicker_Very_Short_ItemCheck(object sender, DevExpress.XtraEditors.Controls.ItemCheckEventArgs e)
        {
            if (isRead) return;
            var txtEdit = sender as CheckedListBoxControl;
            if (string.IsNullOrEmpty(txtEdit.Text)) return;

            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.SelectedValue.ToString());
                SetHDRAeRegister(model, Val);
            }
        }

        private void HDRAE_SpeedModeradio_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (isRead) return;
            var txtEdit = sender as RadioGroup;
            if (string.IsNullOrEmpty(txtEdit.Text)) return;

            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Properties.Items[txtEdit.SelectedIndex].Value.ToString());
                SetHDRAeRegister(model, Val);
            }
        }

        private void slow_b2d_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                slow_b2d_Leave(sender, null);
            }
        }

        private void slow_b2d_Leave(object sender, EventArgs e)
        {
            if (isRead) return;
            var txtEdit = sender as DevExpress.XtraEditors.TextEdit;
            if (string.IsNullOrEmpty(txtEdit.Text)) return;

            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
        }

        private void speed_mode_man_en_CheckedChanged(object sender, EventArgs e)
        {
            var chk = sender as CheckEdit;
            if (isRead) return;
            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == (chk.Name).ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == (chk.Name).ToLower());
                var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
                var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), false);
                SetHDRAeRegister(model, Val);
            }
            if (chk.Checked)
            {
                if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"HDRAE_SpeedModeradio".ToLower()))
                {
                    var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"HDRAE_SpeedModeradio".ToLower());
                    var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, "1");
                    SetHDRAeRegister(model, Val);
                }
            }
            else
            {
                if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"HDRAE_SpeedModeradio".ToLower()))
                {
                    var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"HDRAE_SpeedModeradio".ToLower());
                    var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, "0");
                    SetHDRAeRegister(model, Val);
                }
            }  
            
            EnShowHide();
            //if (chk.Checked)
            //{
            //    if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{HDRAE_SpeedModeradio.Name}".ToLower()))
            //    {
            //        var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{HDRAE_SpeedModeradio.Name}".ToLower());
            //        var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, "1".ToString());
            //        SetHDRAeRegister(model, Val);
            //    }
            //}
        }

        private void trigger_timer_en_CheckedChanged(object sender, EventArgs e)
        {
            var chk = sender as CheckEdit;
            if (isRead) return;
            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == (chk.Name).ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == (chk.Name).ToLower());
                var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
                var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), chk.Checked);
                SetHDRAeRegister(model, Val);
            }
        }

        private void adaptive_en_CheckedChanged(object sender, EventArgs e)
        {
            var chk = sender as CheckEdit;
            if (isRead) return;
            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == (chk.Name).ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == (chk.Name).ToLower());
                var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
                var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), chk.Checked);
                SetHDRAeRegister(model, Val);
            }
            Statusvalue();
        }

        private void Statusvalue()
        {
            if (combine_preferLong_en.Checked)
            {
                weight_hds_en.Enabled = true;
                weight_gain_en.Enabled = true;
                weight_man_en.Enabled = true;
            }
            else
            {
                weight_hds_en.Enabled = false;
                weight_gain_en.Enabled = false;
                weight_man_en.Enabled = false;
            }
            if (weight_hds_en.Checked || weight_gain_en.Checked || weight_man_en.Checked)
            {
                combine_preferLong_str.Enabled = false;
            }
            else
            {
                combine_preferLong_str.Enabled = true;
            }
            if (adaptiveTotal_en.Checked)
            {
                //L_number_adaptive_en.Enabled = true;
                TargetY_L_adaptive_en.Enabled = true;
                TargetY_S_adaptive_en.Enabled = true;

                adaptive_dr_table_01.Enabled = true;
                adaptive_dr_table_02.Enabled = true;
                adaptive_dr_table_03.Enabled = true;
                adaptive_dr_table_04.Enabled = true;
                adaptive_dr_table_05.Enabled = true;
                adaptive_dr_table_06.Enabled = true;
                adaptive_dr_table_07.Enabled = true;
                adaptive_dr_table_08.Enabled = true;

                //L_number_adaptive_01.Enabled = true;
                //L_number_adaptive_02.Enabled = true;
                //L_number_adaptive_03.Enabled = true;
                //L_number_adaptive_04.Enabled = true;
                //L_number_adaptive_05.Enabled = true;
                //L_number_adaptive_06.Enabled = true;
                //L_number_adaptive_07.Enabled = true;
                //L_number_adaptive_08.Enabled = true;

                TargetY_L_adaptive_01.Enabled = true;
                TargetY_L_adaptive_02.Enabled = true;
                TargetY_L_adaptive_03.Enabled = true;
                TargetY_L_adaptive_04.Enabled = true;
                TargetY_L_adaptive_05.Enabled = true;
                TargetY_L_adaptive_06.Enabled = true;
                TargetY_L_adaptive_07.Enabled = true;
                TargetY_L_adaptive_08.Enabled = true;

                TargetY_S_adaptive_01.Enabled = true;
                TargetY_S_adaptive_02.Enabled = true;
                TargetY_S_adaptive_03.Enabled = true;
                TargetY_S_adaptive_04.Enabled = true;
                TargetY_S_adaptive_05.Enabled = true;
                TargetY_S_adaptive_06.Enabled = true;
                TargetY_S_adaptive_07.Enabled = true;
                TargetY_S_adaptive_08.Enabled = true;
                //if (L_number_adaptive_en.Checked)
                //{
                //    //adaptive_dr_table_01.Enabled = true;
                //    //adaptive_dr_table_02.Enabled = true;
                //    //adaptive_dr_table_03.Enabled = true;
                //    //adaptive_dr_table_04.Enabled = true;
                //    //adaptive_dr_table_05.Enabled = true;
                //    //adaptive_dr_table_06.Enabled = true;
                //    //adaptive_dr_table_07.Enabled = true;
                //    //adaptive_dr_table_08.Enabled = true;

                //    L_number_adaptive_01.Enabled = true;
                //    L_number_adaptive_02.Enabled = true;
                //    L_number_adaptive_03.Enabled = true;
                //    L_number_adaptive_04.Enabled = true;
                //    L_number_adaptive_05.Enabled = true;
                //    L_number_adaptive_06.Enabled = true;
                //    L_number_adaptive_07.Enabled = true;
                //    L_number_adaptive_08.Enabled = true;

                //    L_num.Enabled = false;
                //}
                //else
                //{
                //    //adaptive_dr_table_01.Enabled = false;
                //    //adaptive_dr_table_02.Enabled = false;
                //    //adaptive_dr_table_03.Enabled = false;
                //    //adaptive_dr_table_04.Enabled = false;
                //    //adaptive_dr_table_05.Enabled = false;
                //    //adaptive_dr_table_06.Enabled = false;
                //    //adaptive_dr_table_07.Enabled = false;
                //    //adaptive_dr_table_08.Enabled = false;

                //    L_number_adaptive_01.Enabled = false;
                //    L_number_adaptive_02.Enabled = false;
                //    L_number_adaptive_03.Enabled = false;
                //    L_number_adaptive_04.Enabled = false;
                //    L_number_adaptive_05.Enabled = false;
                //    L_number_adaptive_06.Enabled = false;
                //    L_number_adaptive_07.Enabled = false;
                //    L_number_adaptive_08.Enabled = false;

                //    L_num.Enabled = true;
                //}
                if (TargetY_L_adaptive_en.Checked)
                {
                    TargetY_L_adaptive_01.Enabled = true;
                    TargetY_L_adaptive_02.Enabled = true;
                    TargetY_L_adaptive_03.Enabled = true;
                    TargetY_L_adaptive_04.Enabled = true;
                    TargetY_L_adaptive_05.Enabled = true;
                    TargetY_L_adaptive_06.Enabled = true;
                    TargetY_L_adaptive_07.Enabled = true;
                    TargetY_L_adaptive_08.Enabled = true;

                    TargetY_L_ex.Enabled = false;
                }
                else
                {
                    TargetY_L_adaptive_01.Enabled = false;
                    TargetY_L_adaptive_02.Enabled = false;
                    TargetY_L_adaptive_03.Enabled = false;
                    TargetY_L_adaptive_04.Enabled = false;
                    TargetY_L_adaptive_05.Enabled = false;
                    TargetY_L_adaptive_06.Enabled = false;
                    TargetY_L_adaptive_07.Enabled = false;
                    TargetY_L_adaptive_08.Enabled = false;


                    TargetY_L_ex.Enabled = true;
                }
                if (TargetY_S_adaptive_en.Checked)
                {
                    TargetY_S_adaptive_01.Enabled = true;
                    TargetY_S_adaptive_02.Enabled = true;
                    TargetY_S_adaptive_03.Enabled = true;
                    TargetY_S_adaptive_04.Enabled = true;
                    TargetY_S_adaptive_05.Enabled = true;
                    TargetY_S_adaptive_06.Enabled = true;
                    TargetY_S_adaptive_07.Enabled = true;
                    TargetY_S_adaptive_08.Enabled = true;

                    TargetY_S_ex.Enabled = false;
                }
                else
                {

                    TargetY_S_adaptive_01.Enabled = false;
                    TargetY_S_adaptive_02.Enabled = false;
                    TargetY_S_adaptive_03.Enabled = false;
                    TargetY_S_adaptive_04.Enabled = false;
                    TargetY_S_adaptive_05.Enabled = false;
                    TargetY_S_adaptive_06.Enabled = false;
                    TargetY_S_adaptive_07.Enabled = false;
                    TargetY_S_adaptive_08.Enabled = false;


                    TargetY_S_ex.Enabled = true;
                }
            }
            else
            {
                //L_number_adaptive_en.Enabled = false;
                TargetY_L_adaptive_en.Enabled = false;
                TargetY_S_adaptive_en.Enabled = false;

                adaptive_dr_table_01.Enabled = false;
                adaptive_dr_table_02.Enabled = false;
                adaptive_dr_table_03.Enabled = false;
                adaptive_dr_table_04.Enabled = false;
                adaptive_dr_table_05.Enabled = false;
                adaptive_dr_table_06.Enabled = false;
                adaptive_dr_table_07.Enabled = false;
                adaptive_dr_table_08.Enabled = false;

                //L_number_adaptive_01.Enabled = false;
                //L_number_adaptive_02.Enabled = false;
                //L_number_adaptive_03.Enabled = false;
                //L_number_adaptive_04.Enabled = false;
                //L_number_adaptive_05.Enabled = false;
                //L_number_adaptive_06.Enabled = false;
                //L_number_adaptive_07.Enabled = false;
                //L_number_adaptive_08.Enabled = false;

                TargetY_L_adaptive_01.Enabled = false;
                TargetY_L_adaptive_02.Enabled = false;
                TargetY_L_adaptive_03.Enabled = false;
                TargetY_L_adaptive_04.Enabled = false;
                TargetY_L_adaptive_05.Enabled = false;
                TargetY_L_adaptive_06.Enabled = false;
                TargetY_L_adaptive_07.Enabled = false;
                TargetY_L_adaptive_08.Enabled = false;

                TargetY_S_adaptive_01.Enabled = false;
                TargetY_S_adaptive_02.Enabled = false;
                TargetY_S_adaptive_03.Enabled = false;
                TargetY_S_adaptive_04.Enabled = false;
                TargetY_S_adaptive_05.Enabled = false;
                TargetY_S_adaptive_06.Enabled = false;
                TargetY_S_adaptive_07.Enabled = false;
                TargetY_S_adaptive_08.Enabled = false;

                //L_num.Enabled = true;
                TargetY_L_ex.Enabled = true;
                TargetY_S_ex.Enabled = true;
            }
            
        }

        private void L_number_adaptive_en_CheckedChanged(object sender, EventArgs e)
        {
            var chk = sender as CheckEdit;
            if (isRead) return;
            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == (chk.Name).ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == (chk.Name).ToLower());
                var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
                var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), chk.Checked);
                SetHDRAeRegister(model, Val);
            }
            Statusvalue();
        }

        private void TargetY_L_adaptive_en_CheckedChanged(object sender, EventArgs e)
        {
            var chk = sender as CheckEdit;
            if (isRead) return;
            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == (chk.Name).ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == (chk.Name).ToLower());
                var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
                var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), chk.Checked);
                SetHDRAeRegister(model, Val);
            }
            Statusvalue();
        }

        private void TargetY_S_adaptive_en_CheckedChanged(object sender, EventArgs e)
        {
            var chk = sender as CheckEdit;
            if (isRead) return;
            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == (chk.Name).ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == (chk.Name).ToLower());
                var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
                var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), chk.Checked);
                SetHDRAeRegister(model, Val);
            }
            Statusvalue();
        }

        private void AE_WEIGHT_EN_CheckedChanged(object sender, EventArgs e)
        {
            //if (AE_WEIGHT_EN.Checked)
            //{

            //    for (int i = 0; i < 64; i++)
            //    {
            //        foreach (Control item in panelControl1.Controls)
            //        {
            //            if ($"Area_Weight_{(i + 1).ToString("D2")}" == item.Name)
            //            {
            //                item.Enabled = true;
            //            }
            //        }
            //    }
            //}
            //else
            //{
            //    for (int i = 0; i < 64; i++)
            //    {
            //        foreach (Control item in panelControl1.Controls)
            //        {
            //            if ($"Area_Weight_{(i + 1).ToString("D2")}" == item.Name)
            //            {
            //                item.Enabled = false;
            //            }
            //        }
            //    }
            //}
        }

        private void Isp_Gain_en_CheckedChanged(object sender, EventArgs e)
        {
            var chk = sender as CheckEdit;
            if (isRead) return;
            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == (chk.Name).ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == (chk.Name).ToLower());
                var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
                var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), chk.Checked);
                SetHDRAeRegister(model, Val);
            }
        }

        private void factor_Leave(object sender, EventArgs e)
        {
            if (isRead) return;
            var txtEdit = sender as DevExpress.XtraEditors.TextEdit;
            if (string.IsNullOrEmpty(txtEdit.Text)) return;

            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}_h".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}_h".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}_m1".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}_m1".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}_m0".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}_m0".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
            if (XChipHDRAe.Exists(c => c.NameType.ToLower() == $"{txtEdit.Name}_l".ToLower()))
            {
                var model = XChipHDRAe.Find(c => c.NameType.ToLower() == $"{txtEdit.Name}_l".ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtEdit.Text);
                SetHDRAeRegister(model, Val);
            }
        }

        private void factor_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                Max_Gain_Leave(sender, null);
            }
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {

            if (!sPortTemp.IsOpen && !IsUsbOpen && !m_open)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show("可用端口未打开");
                return;
            }
            
            List<string> listfiltration = new List<string> { "L_num", "DR", "TargetY_L_ex", "TargetY_S_ex" };

            isRead = true;
            WaitBefore.Start("读取中", "正在加载中", 10);
            List<string> NameList = new List<string>();

            for (int i = 0; i < xChipHDRAe.Count; i++)
            {
                if (xChipHDRAe[i].NameType.Contains("TargetY_L"))
                {

                }
                var type = AppHelper.NameTypeToString(xChipHDRAe[i].NameType);
                if (NameList.Exists(c => c.ToLower() == (type)))
                {
                    continue;
                }

                ////加上单选框的_en
                //if (xChipHDRAe[i].ControlType == "1")
                //{
                //    type = xChipHDRAe[i].NameType;
                //}
                var col = Controls_Find(type);

                foreach (var item in col)
                {
                    if (!listfiltration.Any(itemss => item.Name==(itemss)))
                    {
                        continue;
                    }
                    if (item is TextEdit)
                    {
                        var nList = xChipHDRAe.Where(c => c.NameType.ToLower().Contains(item.Name.ToString().ToLower()) && c.ControlType == "0").ToList();
                        if (item.Name.ToLower() == type.ToLower())
                        {
                            nList = xChipHDRAe.Where(c => c.NameType.ToLower() == (item.Name.ToString().ToLower()) && c.ControlType == "0").ToList();
                        }
                        if (nList.Count == 0)
                        {
                            nList = xChipHDRAe.Where(c => c.NameType.ToLower().Contains(item.Name.ToString().ToLower()) && c.ControlType == "0").ToList();
                        }
                        if (nList.Count == 1)
                        {
                            var Val = SerialSend.ReadRegister(Convert.ToUInt32(nList[0].Address, 16), sPortTemp).ToString("X");
                            item.Text = BitsHelp.GetBitsToUint(nList[0].Bits, nList[0].Hex, Val).ToString("X");
                        }
                        else
                        {
                            string Val = string.Empty;
                            //这里默认为是有多个寄存器  一个文本框的情况进行处理
                            if (nList.Exists(c => c.NameType.ToLower().Contains("_h")))
                            {
                                Val += SerialSend.ReadRegister(Convert.ToUInt32(nList.Find(c => c.NameType.ToLower().Contains("_h")).Address, 16), sPortTemp).ToString("X2");
                            }
                            if (nList.Exists(c => c.NameType.ToLower().Contains("_m1")))
                            {
                                Val += SerialSend.ReadRegister(Convert.ToUInt32(nList.Find(c => c.NameType.ToLower().Contains("_m1")).Address, 16), sPortTemp).ToString("X2");
                            }
                            if (nList.Exists(c => c.NameType.ToLower().Contains("_m0")))
                            {
                                Val += SerialSend.ReadRegister(Convert.ToUInt32(nList.Find(c => c.NameType.ToLower().Contains("_m0")).Address, 16), sPortTemp).ToString("X2");
                            }
                            if (nList.Exists(c => c.NameType.ToLower().Contains("_l")))
                            {
                                if (nList.Exists(c => c.NameType.ToLower().Substring(c.NameType.Length - 2).Contains("_l")))
                                {
                                    Val += SerialSend.ReadRegister(Convert.ToUInt32(nList.Find(c => c.NameType.ToLower().Substring(c.NameType.Length - 2).Contains("_l")).Address, 16), sPortTemp).ToString("X2");
                                }
                                else
                                {
                                    Val += SerialSend.ReadRegister(Convert.ToUInt32(nList.Last(c => c.NameType.ToLower().Contains("_l")).Address, 16), sPortTemp).ToString("X2");
                                }
                            }

                            item.Text = Val;
                        }
                    }
                    else if (item is CheckEdit)
                    {
                        var nList = xChipHDRAe.Where(c => c.NameType.ToLower().Contains(item.Name.ToString().ToLower()) && c.ControlType == "1").ToList();
                        if (nList.Count == 1)
                        {
                            var Val = SerialSend.ReadRegister(Convert.ToUInt32(nList[0].Address, 16), sPortTemp).ToString("X");
                            (item as CheckEdit).Checked = BitsHelp.GetBitsCheckedToBool(nList[0].Bits, nList[0].Hex, Val) == 0;
                        }
                    }
                    NameList.Add(item.Name);

                }

                //NameList.Add(type);
            }
            isRead = false;
            WaitBefore.Close();
        }

        private void simpleButton6_Click(object sender, EventArgs e)
        {

        }

        private void avg_wave_KeyDown(object sender, KeyEventArgs e)
        {

        }

        private void avg_wave_Leave(object sender, EventArgs e)
        {
            if (isWrite) return;
            //if (null != sPortTemp && sPortTemp.IsOpen)
            {
                if (isRead) return;
                var txt = sender as DevExpress.XtraEditors.TextEdit;
                if (string.IsNullOrEmpty(txt.Text)) return;
                if (XChipHDR.Exists(c => c.NameType.ToLower() == txt.Name.ToLower()))
                {
                    var model = XChipHDR.Find(c => c.NameType.ToLower() == txt.Name.ToLower());
                    var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txt.Text);
                    SetHDRRegister(model, Val);
                }
            }
        }

        private void SetHDRRegister(addressregister model, ulong add, bool isCheck = true)
        {
            if (isRead) return;
            if (IsUsbOpen)
            {
                if (null != BinHelp.usbList)
                {
                    uint pVule = 0x0;
                    var isbool = false;
                    if (IntPtr.Size == 8)
                    {
                        isbool = XChipUSB.UsbRegisterRead64(BinHelp.CurrentSize, ref pVule, true);
                        SerialSend.Sendser("R:0x" + (BinHelp.CurrentSize).ToString("X2"), pVule.ToString("X2"));


                    }
                    else
                    {
                        isbool = XChipUSB.UsbRegisterRead86(BinHelp.CurrentSize, ref pVule, true);
                        SerialSend.Sendser("R:0x" + (BinHelp.CurrentSize).ToString("X2"), pVule.ToString("X2"));
                    }
                    var chang = (int)(pVule >> 16); // 使用右移16位操作来获取高16位  
                    var kuang = (int)(pVule & 0xFFFF); // 使用位与操作来获取低16位  

                    BinHelp.SstBinUsbUpdateData(ref BinHelp.BinList, model.Address, add.ToString("X"), chang, kuang);
                }
            }
            else
            {
                if (!sPortTemp.IsOpen && !IsUsbOpen && !m_open)//串口检测
                {
                    DevExpress.XtraEditors.XtraMessageBox.Show("串口未打开");
                    return;
                }
                if (isRead) return;
                if (null != BinHelp.lspList)
                { //编写Bin更新数据
                    var temp = SerialSend.ReadRegister(BinHelp.BootSettingIdx, sPortTemp);
                    BinHelp.SetBinUpdateData(ref BinHelp.BinList, model.Address, add.ToString("X"), (uint)temp);
                }
            }
            SerialSend.WriteRegister(Convert.ToUInt32(model.Address, 16), add, sPortTemp);

        }

        private void avg_list0_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                avg_list0_Leave(sender, null);
            }
        }

        private void avg_list0_Leave(object sender, EventArgs e)
        {
            if (isWrite) return;
            //if (null != sPortTemp && sPortTemp.IsOpen)
            {
                if (isRead) return;
                var txt = sender as DevExpress.XtraEditors.TextEdit;
                if (string.IsNullOrEmpty(txt.Text)) return;
                if (XChipHDR.Exists(c => c.NameType.ToLower() == txt.Name.ToLower()))
                {
                    var model = XChipHDR.Find(c => c.NameType.ToLower() == txt.Name.ToLower());
                    var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txt.Text);
                    SetHDRRegister(model, Val);
                }
            }
        }

        private void gamma_ratiolist0_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                gamma_ratiolist0_Leave(sender, null);
            }
        }

        private void gamma_ratiolist0_Leave(object sender, EventArgs e)
        {
            if (isWrite) return;
            //if (null != sPortTemp && sPortTemp.IsOpen)
            {
                if (isRead) return;
                var txt = sender as DevExpress.XtraEditors.TextEdit;
                if (string.IsNullOrEmpty(txt.Text)) return;
                if (XChipHDR.Exists(c => c.NameType.ToLower() == txt.Name.ToLower()))
                {
                    var model = XChipHDR.Find(c => c.NameType.ToLower() == txt.Name.ToLower());
                    var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txt.Text);
                    SetHDRRegister(model, Val);
                }
            }
        }

        private void tome_mappinglist0_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                tome_mappinglist0_Leave(sender, null);
            }
        }

        private void tome_mappinglist0_Leave(object sender, EventArgs e)
        {
            if (isWrite) return;
            //if (null != sPortTemp && sPortTemp.IsOpen)
            {
                if (isRead) return;
                var txt = sender as DevExpress.XtraEditors.TextEdit;
                if (string.IsNullOrEmpty(txt.Text)) return;
                if (XChipHDR.Exists(c => c.NameType.ToLower() == txt.Name.ToLower() + "_h"))
                {
                    var model = XChipHDR.Find(c => c.NameType.ToLower() == (txt.Name + "_h").ToLower());
                    var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txt.Text);
                    SetHDRRegister(model, Val);
                }
                if (XChipHDR.Exists(c => c.NameType.ToLower() == txt.Name.ToLower() + "_l"))
                {
                    var model = XChipHDR.Find(c => c.NameType.ToLower() == (txt.Name + "_l").ToLower());
                    var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txt.Text);
                    SetHDRRegister(model, Val);
                }
            }
        }

        private void combine_preferLong_str_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                combine_preferLong_str_Leave(sender, null);
            }
        }

        private void combine_preferLong_str_Leave(object sender, EventArgs e)
        {
            if (isWrite) return;
            var txtedit = sender as DevExpress.XtraEditors.TextEdit;
            if (string.IsNullOrEmpty(txtedit.Text)) return;
            if (XChipHDR.Exists(c => c.NameType.ToLower() == txtedit.Name.ToLower()))
            {
                var model = XChipHDR.Find(c => c.NameType.ToLower() == txtedit.Name.ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtedit.Text);
                SetHDRRegister(model, Val);
            }
        }

        private void weight_gainlist0_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                weight_gainlist0_Leave(sender, null);
            }
        }

        private void weight_gainlist0_Leave(object sender, EventArgs e)
        {
            if (isWrite) return;
            //if (null != sPortTemp && sPortTemp.IsOpen)
            {
                if (isRead) return;
                var txt = sender as DevExpress.XtraEditors.TextEdit;
                if (string.IsNullOrEmpty(txt.Text)) return;
                if (XChipHDR.Exists(c => c.NameType.ToLower() == txt.Name.ToLower()))
                {
                    var model = XChipHDR.Find(c => c.NameType.ToLower() == txt.Name.ToLower());
                    var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txt.Text);
                    SetHDRRegister(model, Val);
                }
            }
        }

        private void weight_man_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                weight_man_Leave(sender, null);
            }
        }

        private void weight_man_Leave(object sender, EventArgs e)
        {
            if (isWrite) return;
            //if (null != sPortTemp && sPortTemp.IsOpen)
            {
                if (isRead) return;
                var txt = sender as DevExpress.XtraEditors.TextEdit;
                if (string.IsNullOrEmpty(txt.Text)) return;
                if (XChipHDR.Exists(c => c.NameType.ToLower() == txt.Name.ToLower()))
                {
                    var model = XChipHDR.Find(c => c.NameType.ToLower() == txt.Name.ToLower());
                    var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txt.Text);
                    SetHDRRegister(model, Val);
                }
            }
        }

        private void thresholdl_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                thresholdl_Leave(sender, null);
            }
        }

        private void thresholdl_Leave(object sender, EventArgs e)
        {
            if (isWrite) return;
            //if (null != sPortTemp && sPortTemp.IsOpen)
            {
                if (isRead) return;
                var txt = sender as DevExpress.XtraEditors.TextEdit;
                if (string.IsNullOrEmpty(txt.Text)) return;
                if (XChipHDR.Exists(c => c.NameType.ToLower() == txt.Name.ToLower() + "_h"))
                {
                    var model = XChipHDR.Find(c => c.NameType.ToLower() == (txt.Name + "_h").ToLower());
                    var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txt.Text);
                    SetHDRRegister(model, Val);
                }
                if (XChipHDR.Exists(c => c.NameType.ToLower() == txt.Name.ToLower() + "_l"))
                {
                    var model = XChipHDR.Find(c => c.NameType.ToLower() == (txt.Name + "_l").ToLower());
                    var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txt.Text);
                    SetHDRRegister(model, Val);
                }
            }
        }

        private void thresholdh_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                thresholdh_Leave(sender, null);
            }
        }

        private void thresholdh_Leave(object sender, EventArgs e)
        {
            if (isWrite) return;
            //if (null != sPortTemp && sPortTemp.IsOpen)
            {
                if (isRead) return;
                var txt = sender as DevExpress.XtraEditors.TextEdit;
                if (string.IsNullOrEmpty(txt.Text)) return;
                if (XChipHDR.Exists(c => c.NameType.ToLower() == txt.Name.ToLower() + "_h"))
                {
                    var model = XChipHDR.Find(c => c.NameType.ToLower() == (txt.Name + "_h").ToLower());
                    var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txt.Text);
                    SetHDRRegister(model, Val);
                }
                if (XChipHDR.Exists(c => c.NameType.ToLower() == txt.Name.ToLower() + "_l"))
                {
                    var model = XChipHDR.Find(c => c.NameType.ToLower() == (txt.Name + "_l").ToLower());
                    var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txt.Text);
                    SetHDRRegister(model, Val);
                }
            }
        }

        private void threshold_num_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                threshold_num_Leave(sender, null);
            }
        }

        private void threshold_num_Leave(object sender, EventArgs e)
        {
            if (isWrite) return;
            //if (null != sPortTemp && sPortTemp.IsOpen)
            {
                if (isRead) return;
                var txt = sender as DevExpress.XtraEditors.TextEdit;
                if (string.IsNullOrEmpty(txt.Text)) return;
                if (XChipHDR.Exists(c => c.NameType.ToLower() == txt.Name.ToLower()))
                {
                    var model = XChipHDR.Find(c => c.NameType.ToLower() == txt.Name.ToLower());
                    var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txt.Text);
                    SetHDRRegister(model, Val);
                }
            }
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            List<string> listfiltration = new List<string> { "exp_ratio_LS_l", "exp_ratio_LS_h", "exp_line_L_l", "exp_line_L_m0", "exp_line_L_h", "gain_L_l", "gain_L_h", "exp_ratio_SV_h", "exp_ratio_SV_l", "exp_line_S_l", "exp_line_S_m0", "exp_line_S_h", "gain_S_l", "gain_S_h", "exp_line_V_l", "exp_line_V_h", "exp_line_V_m0", "gain_V_h", "gain_V_l", "combine_preferLong_str" };
            List<string> NameList = new List<string>();
            for (int i = 0; i < XChipHDR.Count; i++)
            {
                var type = AppHelper.NameTypeToString(XChipHDR[i].NameType);
                //加上单选框的_en
                if (XChipHDR[i].ControlType == "1")
                {
                    type = XChipHDR[i].NameType;
                }
                var col = this.Controls.Find(type, true);
                foreach (var item in col)
                {
                    if (NameList.Exists(c => c.Contains(type)))
                    {
                        continue;
                    }
                    else
                    {

                        //过滤掉指定寄存器
                        if (!listfiltration.Exists(c => c.Contains(item.Name.ToString())))
                        {
                            continue;
                        }
                        if (item is TextEdit)
                        {

                            var nList = XChipHDR.Where(c => c.NameType.ToLower().Contains(item.Name.ToString().ToLower()) && c.ControlType == "0").ToList();
                            if (nList.Count == 1)
                            {
                                var Val = SerialSend.ReadRegister(Convert.ToUInt32(nList[0].Address, 16), sPortTemp).ToString("X");
                                item.Text = BitsHelp.GetBitsToUint(nList[0].Bits, nList[0].Hex, Val).ToString("X");
                            }
                            else
                            {
                                var listsum = nList.Select(c => c.Address).Distinct().ToList();
                                string Val = string.Empty;
                                if (1 == listsum.Count())
                                {

                                }
                                else
                                {

                                }

                                //这里默认为是有多个寄存器  一个文本框的情况进行处理
                                if (nList.Exists(c => c.NameType.ToLower().Contains("_h")))
                                {
                                    Val += SerialSend.ReadRegister(Convert.ToUInt32(nList.Find(c => c.NameType.ToLower().Contains("_h")).Address, 16), sPortTemp).ToString("X2");
                                }
                                if (nList.Exists(c => c.NameType.ToLower().Contains("_m0")))
                                {
                                    Val += SerialSend.ReadRegister(Convert.ToUInt32(nList.Find(c => c.NameType.ToLower().Contains("_m0")).Address, 16), sPortTemp).ToString("X2");
                                }
                                if (nList.Exists(c => c.NameType.ToLower().Substring(c.NameType.Length - 2).Contains("_l")))
                                {
                                    Val += SerialSend.ReadRegister(Convert.ToUInt32(nList.Find(c => c.NameType.ToLower().Substring(c.NameType.Length - 2).Contains("_l")).Address, 16), sPortTemp).ToString("X2");
                                }
                                item.Text = Val;
                            }
                        }
                        else if (item is CheckEdit)
                        {
                            var nList = XChipHDR.Where(c => c.NameType.ToLower().Contains(item.Name.ToString().ToLower()) && c.ControlType == "1").ToList();
                            if (nList.Count == 1)
                            {
                                var Val = SerialSend.ReadRegister(Convert.ToUInt32(nList[0].Address, 16), sPortTemp).ToString("X");
                                (item as CheckEdit).Checked = BitsHelp.GetBitsCheckedToBool(nList[0].Bits, nList[0].Hex, Val) == 0;
                            }
                        }


                    }
                }
                NameList.Add(type);
            }
        }

        private void Mode_switch_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (Mode_switch.EditValue.ToString() == "1")
            {
                if (XChipHDR.Exists(c => c.NameType.ToLower() == "HDRmode0".ToLower()))
                {
                    var model = XChipHDR.Find(c => c.NameType.ToLower() == "HDRmode0".ToLower());
                    //var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex,"1");
                    var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
                    var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), true);
                    SetHDRRegister(model, Val);
                }
                if (XChipHDR.Exists(c => c.NameType.ToLower() == "HDRmode1".ToLower()))
                {
                    var model = XChipHDR.Find(c => c.NameType.ToLower() == "HDRmode1".ToLower());
                    //var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, "0");
                    var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
                    var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), false);
                    SetHDRRegister(model, Val);
                }
                if (XChipHDR.Exists(c => c.NameType.ToLower() == "HDRmode2".ToLower()))
                {
                    var model = XChipHDR.Find(c => c.NameType.ToLower() == "HDRmode2".ToLower());
                    //var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, "0");
                    var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
                    var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), false);
                    SetHDRRegister(model, Val);
                }
            }
            else if (Mode_switch.EditValue.ToString() == "2")
            {
                if (XChipHDR.Exists(c => c.NameType.ToLower() == "HDRmode0".ToLower()))
                {
                    var model = XChipHDR.Find(c => c.NameType.ToLower() == "HDRmode0".ToLower());
                    //var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, "0");
                    var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
                    var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), false);
                    SetHDRRegister(model, Val);
                }
                if (XChipHDR.Exists(c => c.NameType.ToLower() == "HDRmode1".ToLower()))
                {
                    var model = XChipHDR.Find(c => c.NameType.ToLower() == "HDRmode1".ToLower());
                    //var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, "0");
                    var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
                    var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), false);
                    SetHDRRegister(model, Val);
                }
                if (XChipHDR.Exists(c => c.NameType.ToLower() == "HDRmode2".ToLower()))
                {
                    var model = XChipHDR.Find(c => c.NameType.ToLower() == "HDRmode2".ToLower());
                    //var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, "0");
                    var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
                    var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), false);
                    SetHDRRegister(model, Val);
                }
            }
            else if (Mode_switch.EditValue.ToString() == "3")
            {
                if (XChipHDR.Exists(c => c.NameType.ToLower() == "HDRmode0".ToLower()))
                {
                    var model = XChipHDR.Find(c => c.NameType.ToLower() == "HDRmode0".ToLower());
                    // var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, "0");
                    var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
                    var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), false);
                    SetHDRRegister(model, Val);
                }
                if (XChipHDR.Exists(c => c.NameType.ToLower() == "HDRmode1".ToLower()))
                {
                    var model = XChipHDR.Find(c => c.NameType.ToLower() == "HDRmode1".ToLower());
                    // var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, "1");
                    var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
                    var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), true);
                    SetHDRRegister(model, Val);
                }
                if (XChipHDR.Exists(c => c.NameType.ToLower() == "HDRmode2".ToLower()))
                {
                    var model = XChipHDR.Find(c => c.NameType.ToLower() == "HDRmode2".ToLower());
                    // var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, "0");
                    var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
                    var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), false);
                    SetHDRRegister(model, Val);
                }
            }
            else if (Mode_switch.EditValue.ToString() == "4")
            {
                if (XChipHDR.Exists(c => c.NameType.ToLower() == "HDRmode0".ToLower()))
                {
                    var model = XChipHDR.Find(c => c.NameType.ToLower() == "HDRmode0".ToLower());
                    //var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, "0");
                    var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
                    var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), false);
                    SetHDRRegister(model, Val);
                }
                if (XChipHDR.Exists(c => c.NameType.ToLower() == "HDRmode1".ToLower()))
                {
                    var model = XChipHDR.Find(c => c.NameType.ToLower() == "HDRmode1".ToLower());
                    //var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, "0");
                    var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
                    var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), false);
                    SetHDRRegister(model, Val);
                }
                if (XChipHDR.Exists(c => c.NameType.ToLower() == "HDRmode2".ToLower()))
                {
                    var model = XChipHDR.Find(c => c.NameType.ToLower() == "HDRmode2".ToLower());
                    //var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, "1");
                    var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
                    var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), true);
                    SetHDRRegister(model, Val);
                }
            }
        }

        private void gamma_ratio_en_CheckedChanged(object sender, EventArgs e)
        {
            var chk = sender as CheckEdit;
            if (isRead) return;
            if (XChipHDR.Exists(c => c.NameType.ToLower() == (chk.Name).ToLower()))
            {
                var model = XChipHDR.Find(c => c.NameType.ToLower() == (chk.Name).ToLower());
                var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
                var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), chk.Checked);
                SetHDRRegister(model, Val);
            }
            EnShowHide();
        }

        private void tome_mapping_en_CheckedChanged(object sender, EventArgs e)
        {
            var chk = sender as CheckEdit;
            if (isRead) return;
            if (XChipHDR.Exists(c => c.NameType.ToLower() == (chk.Name).ToLower()))
            {
                var model = XChipHDR.Find(c => c.NameType.ToLower() == (chk.Name).ToLower());
                var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
                var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), chk.Checked);
                SetHDRRegister(model, Val);
            }
            Statusvalue();
            EnShowHide();
        }

        private void combine_preferLong_en_CheckedChanged(object sender, EventArgs e)
        {
            var chk = sender as CheckEdit;
            if (isRead) return;
            if (XChipHDR.Exists(c => c.NameType.ToLower() == (chk.Name).ToLower()))
            {
                var model = XChipHDR.Find(c => c.NameType.ToLower() == (chk.Name).ToLower());
                var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
                var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), chk.Checked);
                SetHDRRegister(model, Val);
            }
            Statusvalue();
            EnShowHide();

        }

        private void weight_gain_en_CheckedChanged(object sender, EventArgs e)
        {
            var chk = sender as CheckEdit;
            if (isRead) return;
            if (XChipHDR.Exists(c => c.NameType.ToLower() == (chk.Name).ToLower()))
            {
                var model = XChipHDR.Find(c => c.NameType.ToLower() == (chk.Name).ToLower());
                var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
                var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), chk.Checked);
                SetHDRRegister(model, Val);
            }
            Statusvalue();
            EnShowHide();
        }

        private void weight_hds_en_CheckedChanged(object sender, EventArgs e)
        {
            var chk = sender as CheckEdit;
            if (isRead) return;
            if (XChipHDR.Exists(c => c.NameType.ToLower() == (chk.Name).ToLower()))
            {
                var model = XChipHDR.Find(c => c.NameType.ToLower() == (chk.Name).ToLower());
                var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
                var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), chk.Checked);
                SetHDRRegister(model, Val);
            }
            Statusvalue();
            EnShowHide();
        }

        private void weight_man_en_CheckedChanged(object sender, EventArgs e)
        {
            var chk = sender as CheckEdit;
            if (isRead) return;
            if (XChipHDR.Exists(c => c.NameType.ToLower() == (chk.Name).ToLower()))
            {
                var model = XChipHDR.Find(c => c.NameType.ToLower() == (chk.Name).ToLower());
                var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
                var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), chk.Checked);
                SetHDRRegister(model, Val);
            }
            Statusvalue();
            EnShowHide();
        }
        private void EnShowHide()
        {
            if (Flicker_Long.Items[0].CheckState == CheckState.Checked)//50hz
            {
                Flicker_50Hz.Enabled = true;
                Flicker_60Hz.Enabled = false;
            }
            if (Flicker_Long.Items[1].CheckState == CheckState.Checked)//60hz
            {
                Flicker_50Hz.Enabled = false;
                Flicker_60Hz.Enabled = true;
            }
            if ((Flicker_Long.Items[1].CheckState == CheckState.Unchecked) && (Flicker_Long.Items[0].CheckState == CheckState.Unchecked))//均不勾选
            {
                Flicker_50Hz.Enabled = false;
                Flicker_60Hz.Enabled = false;
            }

            slow_b2d.Enabled = speed_mode_man_en.Checked;
            slow_d2b.Enabled = speed_mode_man_en.Checked;

            gamma_ratiolist0.Enabled = gamma_ratio_en.Checked;
            gamma_ratiolist1.Enabled = gamma_ratio_en.Checked;
            gamma_ratiolist2.Enabled = gamma_ratio_en.Checked;
            gamma_ratiolist3.Enabled = gamma_ratio_en.Checked;
            gamma_ratiolist4.Enabled = gamma_ratio_en.Checked;
            gamma_ratiolist5.Enabled = gamma_ratio_en.Checked;
            gamma_ratiolist6.Enabled = gamma_ratio_en.Checked;
            gamma_ratiolist7.Enabled = gamma_ratio_en.Checked;

            tome_mappinglist0.Enabled = tome_mapping_en.Checked;
            tome_mappinglist1.Enabled = tome_mapping_en.Checked;
            tome_mappinglist2.Enabled = tome_mapping_en.Checked;
            tome_mappinglist3.Enabled = tome_mapping_en.Checked;
            tome_mappinglist4.Enabled = tome_mapping_en.Checked;
            tome_mappinglist5.Enabled = tome_mapping_en.Checked;
            tome_mappinglist6.Enabled = tome_mapping_en.Checked;
            tome_mappinglist7.Enabled = tome_mapping_en.Checked;

            combine_preferLong_str.Enabled = combine_preferLong_en.Checked;

            weight_gainlist0.Enabled = weight_gain_en.Checked;
            weight_gainlist1.Enabled = weight_gain_en.Checked;
            weight_gainlist2.Enabled = weight_gain_en.Checked;
            weight_gainlist3.Enabled = weight_gain_en.Checked;
            weight_gainlist4.Enabled = weight_gain_en.Checked;
            weight_gainlist5.Enabled = weight_gain_en.Checked;
            weight_gainlist6.Enabled = weight_gain_en.Checked;
            weight_gainlist7.Enabled = weight_gain_en.Checked;
            weight_gainlist8.Enabled = weight_gain_en.Checked;

            weight_man.Enabled = weight_man_en.Checked;

            thresholdl.Enabled = weight_hds_en.Checked;
            thresholdh.Enabled = weight_hds_en.Checked;
            threshold_num.Enabled = weight_hds_en.Checked;
        }
        
    }
}
